<?php
namespace Admin\Controller;
class TypeAttrController extends CommonController {
	private $model;
	public function __auto() {
		$this -> model = new \Common\Model\TypeAttr;
	}

	//显示商品属性列表
	public function index() {
		//获得点击类型的get参数tid
		$tid = Q('get.tid');
		$attr = $this -> model -> where(array('tid' => $tid)) -> get();
		View::with('attr', $attr);
		View::make();
	}

	//商品属性添加
	public function add() {
		$tid = Q('get.tid');
		if (IS_POST) {
			if ($this -> model -> store($tid)) {
				View::success('添加成功', U('index', array('tid' => $_POST['tid'])));
			}
			View::error($this -> model -> getError());
		}

		View::make();
	}

	//商品属性删除
	public function del() {
		$taid = Q('get.taid');
		if ($this -> model -> del($taid)) {
			View::success('删除成功',U('Type/index'));
		}
		View::error($this -> model -> getError());
	}

	//商品属性修改
	public function edit() {
		$taid = Q('get.taid');
		$tid = Q('get.tid');
		if (IS_POST) {
			if ($this -> model -> edit($taid)) {
				View::success('修改成功', U('index', array('tid' => $tid)));
			}
			View::error($this->model->getError());
		}
		$value=$this->model->where(array('taid'=>$taid))->pluck('tavalue');
		$tavalue=str_replace(',', '|', $value);
		$oldData=$this->model->where(array('taid'=>$taid))->find();
		$oldData['tavalue']=$tavalue;
//		p($oldData);die;
		View::with('oldData',$oldData);
		View::make();

	}

}
?>